from wordcloud import WordCloud,STOPWORDS
import jieba
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

filename = 'word.txt'
with open(filename,encoding='utf-8') as f:
    mytext = f.read()
cut_text =''.join(jieba.lcut(mytext))


cloud = WordCloud(
    background_color='white',
    mask=np.array(Image.open("timg.jpg")),
    font_path='simhei.ttf',
    max_words=50,
    stopwords=STOPWORDS,
    max_font_size=150,
    random_state=30
)
word_cloud = cloud.generate(cut_text)
plt.imshow(word_cloud)
plt.axis('off')
plt.show()